<?php
require_once '../includes/include_dao.php';

if ($_POST['submit-action'] == 'form_edit') :
	//print_r($_REQUEST);
	$template = DAOFactory::getTemplateDAO()->load($_POST['template']); 
	$template->title = $_POST['title']; 
	$template->document = $_POST['document']; 
	$template->updated = date('Y-m-d H:i:s'); 
	DAOFactory::getTemplateDAO()->update($template); 
endif;

$path_form = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) :
	$path_form .= '?' . htmlentities($_SERVER['QUERY_STRING']);
endif;

$template = DAOFactory::getTemplateDAO()->load($_GET['template']); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit Template</title>
<link href="../includes/css/screen.css" type="text/css" rel="stylesheet" media="screen,projection" />
</head>
<body>
<div id="layout">
  <div id="header">
    <h1 id="logo"><a href="/" title="Access the HOME page">sparked<span> </span></a></h1>
    <hr class="noscreen" />
    <div id="navigation">
      <ul>
        <li><a href="/" title="HOME">HOME</a></li>
        <li><a href="/templates.php" title="TEMPLATES">TEMPLATES</a></li>
        <li><a href="/tags.php" title="TAGS">TAGS</a></li>
      </ul>
    </div>
    <hr class="noscreen" />
  </div>
  <div class="banner-box">
    <div class="banner-box-content">
      <div class="content">
        <h2><?php echo $template->title; ?></h2>
        <p>The kickstart file (template) is used to allow for automated installations. It can be downloaded using it's defined tags.</p>
        <?php if ($template) : ?>
        <a href="/template.php?template=<?php echo $template->template; ?>" class="light">View</a> <a href="/template/delete.php?template=<?php echo $template->template; ?>&amp;action=delete" class="light">Delete</a>
        <?php endif; ?>
      </div>
      <div id="box-right">
        <div id="box-right-content">
          <p><span> Last Updated</span><br />
            <?php echo $template->updated; ?></p>
        </div>
      </div>
    </div>
    <div class="banner-bottom"></div>
  </div>
  <div id="main">
    <?php if ($template) : ?>
    <h2>Edit Template</h2>
    <form action="<?php echo $path_form; ?>" method="post" name="form_insert" id="form_insert">
      <h3>Title</h3>
      <input name="title" type="text" id="title" value="<?php echo $template->title; ?>" />
      <h3>Template Document</h3>
      <textarea name="document" cols="75" rows="30" wrap="virtual"><?php echo $template->document; ?></textarea>
      <p>
        <input type="hidden" name="template" value="<?php echo $template->template; ?>" />
        <input type="hidden" name="submit-action" value="form_edit" />
        <input name="submit" type="submit" value="Save" class="button-big" />
        <input type="reset" name="reset" value="Reset" class="button-big" />
      </p>
    </form>
    <?php else :
	echo 'Error - no kickstart';
endif;
?>
  </div>
</div>
<div id="footer">
  <div id="footer-inside">
    <p id="copyright"><a href="http://code.google.com/p/sparked/" title="View Google Code Project" target="_blank">&copy;<?php echo date('Y'); ?> All Rights Reserved.</a></p>
  </div>
  <div style="clear: both;"></div>
</div>
</body>
</html>
